package com.crr.mall.product.app;

import java.util.Arrays;
import java.util.Map;

import cn.hutool.core.bean.BeanUtil;
import com.crr.mall.common.bean.ResultBean;
import com.crr.mall.common.utils.BaseController;
import com.crr.mall.product.query.SkuQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.crr.mall.product.entity.SkuEntity;
import com.crr.mall.product.service.SkuService;
import com.crr.mall.common.utils.PageUtils;
import com.crr.mall.common.utils.R;



/**
 * sku信息
 *
 * @author chenrenren
 * @email chenrenren@gmail.com
 * @date 2024-11-22 14:50:19
 */
@RestController
@RequestMapping("product/sku")
public class SkuController extends BaseController {
    @Autowired
    private SkuService skuService;


    @PostMapping("/listinfo")
    public ResultBean query(@RequestBody SkuQuery skuQuery){
        PageUtils pageUtils = skuService.queryBycondition(BeanUtil.beanToMap(skuQuery));
        return success("sku列表",pageUtils);
    }



    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = skuService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{skuId}")
    public R info(@PathVariable("skuId") Long skuId){
		SkuEntity sku = skuService.getById(skuId);

        return R.ok().put("sku", sku);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody SkuEntity sku){
		skuService.save(sku);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody SkuEntity sku){
		skuService.updateById(sku);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] skuIds){
		skuService.removeByIds(Arrays.asList(skuIds));

        return R.ok();
    }

}
